﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HyEduOnline.Server.Teacher;
using HyEduOnline.Server.Common;
using HyEduOnline.Server.Admin;
using HyEduOnline.Server.Student;
using HyEduOnline.Entities;

namespace WebSite.Areas.WebApi.Controllers
{
    public class AddVaildateController : BaseController
    {
       
        // 验证教职工编号唯一
        public JsonResult TeacherNoValidate(string TeaNO)
        {
            TeachersDAO TeachersDAO = new TeachersDAO();
            List<TbTeachers> list = TeachersDAO.GetByPage("S_TeaNo='" + TeaNO + "'", 0, 20).ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        //验证学号唯一
        public JsonResult StudentNoValidate(string StuNo)
        {
            StudentsDAO StudentsDAO = new StudentsDAO();
            List<TbStudents> list = StudentsDAO.GetByPage("S_No='" + StuNo + "'", 0, 20).ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        //验证班级编号唯一以及是否存在
        public JsonResult AddDeanClass(string SClassCode)
        {
            TList<TbDeanClass> list = new DeanClassDAO().GetByPage("S_ClassCode = '" + SClassCode + "'", 0, int.MaxValue);

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        //验证课程编号唯一
        public JsonResult AddDeanCourse(string SCourseCode)
        {
            TList<TbDeanCourse> list = new DeanCourseDAO().GetByPage("S_CourseCode='" + SCourseCode + "'", 0, 20);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 联动，产生专业名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult AddPros(string collegeCode)
        {
            try
            {
                List<TbDeanCollege> list = new DeanCollegeDAO().GetByPage("S_CollegeCode = '" + collegeCode + "'", 0, int.MaxValue).ToList();
                int id = list[0].Id;
                List<TbDeanCollege> ProList = new DeanCollegeDAO().GetByPage("I_ParentId = " + id, 0, int.MaxValue).ToList();
                return Json(ProList);
            }
            catch (Exception)
            {

                return Json(null);
            }
        }
    }
}
